969efa4790fc6dda3385d966afb5e7bd4e852356
7 * Handle ajax requests and send them to the proper handler.
10 if ( !( defined( 'MEDIAWIKI' ) && $wgUseAjax ) ) {
14 require_once( 'AjaxFunctions.php' );
17 * Object-Oriented Ajax functions.
20 class AjaxDispatcher
{
21 /** Name of the requested handler */
22 private $func_name = null;
24 /** Arguments passed */
25 private $args = array();
27 /** Load up our object with user supplied data */
28 public function __construct( WebRequest
$req ) {
29 wfProfileIn( __METHOD__
);
31 $rs = $req->getVal( 'rs' );
33 $this->func_name
= $rs;
35 $rsargs = $req->getVal( 'rsargs' );
36 if( $rsargs !== null ) {
37 $this->args
= $rsargs;
40 wfProfileOut( __METHOD__
);
43 /** Pass the request to our internal function.
44 * BEWARE! Data are passed as they have been supplied by the user,
45 * they should be carefully handled in the function processing the
48 function performAction() {
49 global $wgAjaxExportList, $wgOut;
51 if ( is_null( $this->func_name
) ) {
55 wfProfileIn( __METHOD__
);
57 if ( ! in_array( $this->func_name
, $wgAjaxExportList ) ) {
58 wfDebug( __METHOD__
. ' Bad Request for unknown function ' . $this->func_name
. "\n" );
63 "unknown function " . (string) $this->func_name
66 wfDebug( __METHOD__
. ' dispatching ' . $this->func_name
. "\n" );
68 if ( strpos( $this->func_name
, '::' ) !== false ) {
69 $func = explode( '::', $this->func_name
, 2 );
71 $func = $this->func_name
;
75 $result = call_user_func_array( $func, $this->args
);
77 if ( $result === false ||
$result === null ) {
78 wfDebug( __METHOD__
. ' ERROR while dispatching '
79 . $this->func_name
. "(" . var_export( $this->args
, true ) . "): "
80 . "no data returned\n" );
82 wfHttpError( 500, 'Internal Error',
83 "{$this->func_name} returned no data" );
85 if ( is_string( $result ) ) {
86 $result = new AjaxResponse( $result );
89 $result->sendHeaders();
92 wfDebug( __METHOD__
. ' dispatch complete for ' . $this->func_name
. "\n" );
94 } catch ( Exception
$e ) {
95 wfDebug( __METHOD__
. ' ERROR while dispatching '
96 . $this->func_name
. "(" . var_export( $this->args
, true ) . "): "
97 . get_class( $e ) . ": " . $e->getMessage() . "\n" );
99 if ( !headers_sent() ) {
100 wfHttpError( 500, 'Internal Error',
103 print $e->getMessage();
108 wfProfileOut( __METHOD__
);